package logic

import (
	"bw-renting/model/mysql"
	"bw-renting/user-rpc/internal/svc"
	"bw-renting/user-rpc/user"
	"context"
	"errors"

	"github.com/zeromicro/go-zero/core/logx"
)

type MobileLoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMobileLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MobileLoginLogic {
	return &MobileLoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// Todo:手机号登录
func (l *MobileLoginLogic) MobileLogin(in *user.MobileLoginReq) (*user.Response, error) {
	// todo: add your logic here and delete this line
	//验证手机号是否注册
	res := mysql.MobileLogin(mysql.User{
		Mobile: in.Mobile,
	})
	if res.ID == 0 {
		return nil, errors.New("手机号未绑定账户")
	}
	return &user.Response{
		UserId: int64(res.ID),
	}, nil
}
